(function( root, factory, plug ) {
	factory( root.jQuery, plug );
})( window, function( $, plug ){
	//定义默认参数
	var _DEFAULTS_ = {
		initEvent: "input",
		dataName: "dr"
	}
	//定义默认配置
	var _RULES_ = {
		required: function( data ) {
			return this.val() ? data : false;
		},
		regexp: function( data ) {
			return new RegExp( data, "g" ).test(this.val());
		},
		"minlength": function( data ) {
			return this.val().length >= data;
		},
		check: function( data ) {
			return this.is(":checked");
		}
	}

	$.fn[ plug ] = function( options ){
		if( !this.is( "form" ) ){ return }
		var _this = this;
		$.fn.extend( this, _DEFAULTS_, _RULES_, options );
		this.$input = $(document).find("input");
		this.$input.on( _this.initEvent, function(){
			verificate( $(this) );
		} );
		this.on( "submit", function(){
		    _this.$input.each(function(k,obj){
				verificate( $( obj ) );
		    });
			return false;
		} );
		var verificate = function( $this ){
				if( $this.is( "input[type=checkbox]" ) ) {
					$this.parent().siblings("p").remove();
				}
				$this.siblings("p").remove();
				$.each( _RULES_, function( key, fn ) {
					var $data = $this.data( _this.dataName + "-" + key );
					if( $data ) {
						var $message = $this.data( _this.dataName + "-" + key + "-message" );
						var result = fn.call( $this, $data );
						if( $this.is( "input[type=checkbox]" ) ) { $this = $this.parent() }
						if( !result ) {
							$this.after( "<p style='color: red; font-size: 14px'>" + $message + "</p>" );
						}
					}
				} );
			}
	}

	$.fn[ plug ].extendPort = function( options ) {
		$.extend( _RULES_, options );
	}


}, "dataVerif" );